package com.example.flow.flow;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @author tangaq
 * 2023/6/16
 */
public class FlowConstant {
    /**
     * 开始节点名称
     */
    public static final String NODE_START = "start";
    /**
     * 结束节点名称
     */
    public static final String NODE_END = "end";

    /**
     * 状态；活动状态
     */
    public static final Integer STATE_ACTIVE = 1;
    /**
     * 状态：结束状态
     */
    public static final Integer STATE_FINISH = 0;
    /**
     * 状态：终止状态
     */
    public static final Integer STATE_TERMINATION = 2;

    /**
     * 审批结果
     */
    public static String KEY_REPLY_RESULT = "reply_result";
    /**
     * 审批参数
     */
    public static String APPROVE_CONTENT = "approve_content";
    /**
     * 申请单号
     */
    public static String APPLY_ID = "apply_id";
    /**
     * 终端编号
     */
    public static String TERMINAL_GUID = "terminal_guid";
    /**
     * 域名
     */
    public static String OUT_DOMAIN = "outDomain";

    /**
     * 是否发送邮箱
     */
    public static String NEED_SEND_NOTIFY = "need_send_notify";
    public static String EMAIL_ID = "email_id";
    /**
     * 当前审批人
     */
    public static String CURRENT_OPERATOR_GUID = "CURRENT_OPERATOR_GUID";

    public enum EnumFlowProcessType {
        file_outgoing("file_outgoing", "outgoingFlow", "文件外发审批"),
        file_decrypt("file_decrypt", "decryptFlow", "文件解密审批"),
        ;
        private final String type;
        private final String dataType;
        private final String desc;

        EnumFlowProcessType(String type, String dataType, String desc) {
            this.type = type;
            this.dataType = dataType;
            this.desc = desc;
        }

        public static EnumFlowProcessType find(String type) {
            if (StringUtils.isBlank(type)) {
                return null;
            }
            return Arrays.stream(EnumFlowProcessType.values())
                    .parallel()
                    .filter(e -> e.getType().equals(type))
                    .findFirst()
                    .orElse(null);
        }

        public static EnumFlowProcessType findByDataType(String dataType) {
            if (StringUtils.isBlank(dataType)) {
                return null;
            }
            return Arrays.stream(EnumFlowProcessType.values())
                    .parallel()
                    .filter(e -> e.getDataType().equals(dataType))
                    .findFirst()
                    .orElse(null);
        }

        public String getType() {
            return type;
        }

        public String getDesc() {
            return desc;
        }

        public String getDataType() {
            return dataType;
        }
    }
}
